<template>
	<view class="content wrap">
		<u-form :model="form" ref="uForm"  :rules="rules">
			<u-form-item label="项目部" label-width="160" left-icon="home"><u-input v-model="form.operateName" type="select" @click="getO()"/></u-form-item>
			
			<u-form-item label="反馈类型" label-width="150">
				<u-radio-group v-model="form.types">
					<u-radio 
						@change="radioChange" 
						v-for="(item, index) in typeslist" :key="index" 
						:name="item.name"
					>
					{{item.name}}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			
			<u-form-item label="内容" label-width="150" prop="contents"><u-input v-model="form.contents" type="textarea" placeholder="请输入内容"/></u-form-item>
			
		</u-form>
		<u-button @click="submit">提交</u-button>
		<view>
			<u-select v-model="show2" :list="olist" @confirm="confirm2"></u-select>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				form:{
				    operateId:'',
				    operateName:"",
				    taskId:"",
					orderNumber:"",
				    types:"举报",
				    contents:"",
				},
				typeslist: [
					{
						name: '举报'
					},
					{
						name: '异常'
					}
				],
				olist:[],
				show2:false,
			    rules: {
					contents: [
						{ 
							required: true,
							message: '请输入内容', 
							trigger: 'blur',
						}
					],
				}
			};
		},
		onLoad(open) {
			this.form.taskId = open.taskId
			this.form.orderNumber = open.orderNumber
			this.$http.post('/rest/operate/list',{
			},{
				params: {},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				this.form.operateId = res.data.data[0].id
				this.form.operateName = res.data.data[0].operateName
				for(let item1 of res.data.data) {
					let obj = {}
					obj.value = item1.id
					obj.label = item1.operateName
					this.olist.push(obj)
				}
			})
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods:{
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
			getO(){
				this.show2 = true
			},
			confirm2(e) {
				this.form.operateId = e[0].value
				this.form.operateName = e[0].label
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						if(typeof this.form.operateId == 'undefined' || this.form.operateId == null || this.form.operateId == ""){
							uni.showToast({
								title: "请选择项目部",
								icon: 'none'
							})
							return
						}
						uni.showLoading({
							title: '正在提交'
						})
						this.$http.post('/rest/feedback/addItem',{
						},{
							params: this.form,
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							if(res.data.code == 200) {
								this.$refs.uToast.show({
									title: '操作成功',
									type: 'success'
								})
								setTimeout(() => {
									this.$Router.back()
								}, 1000)
							} else {
								this.$refs.uToast.show({
									title: res.data.message,
									type: 'error'
								})
							}
						})
					} else {
						console.log('验证失败');
					}
				});
			},
		}
	}
</script>
<style lang="scss">
	page{
			background-color: #ffffff;
	}
	
	.wrap {
		padding: 30rpx;
	}
</style>
